package com.xiaoshuidi.cloud.module.finance.api.invoice;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.module.finance.dal.dataobject.invoice.FinanceInvoiceTaxRateDO;
import com.xiaoshuidi.cloud.module.finance.service.invoice.BaseInvoiceService;
import com.xiaoshuidi.cloud.module.finance.service.invoice.FinanceInvoiceConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

@RestController
@RequiredArgsConstructor
public class InvoiceApiImpl implements InvoiceApi {
    private final FinanceInvoiceConfigService financeInvoiceConfigService;
    private final BaseInvoiceService baseInvoiceService;

    @Override
    public CommonResult<Set<Long>> invoicableFeeId(Integer invoiceConfigId) {
        Set<Long> feeId = financeInvoiceConfigService.getFeeTax(invoiceConfigId).stream()
                .map(FinanceInvoiceTaxRateDO::getFeeId).collect(Collectors.toSet());
        return CommonResult.success(feeId);
    }

    @Override
    public CommonResult<Map<Long, List<Long>>> getInvoiceTaxMap(Collection<Long> apartmentIds) {
        return CommonResult.success(financeInvoiceConfigService.getFeeTaxMap(apartmentIds));
    }

    @Override
    public CommonResult<List<Long>> invoiceRed(List<Long> orderIds) {
        return CommonResult.success(baseInvoiceService.invoiceRedForOrderIds(orderIds));
    }
}
